home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / codelib9 / v_11_05 / test_obj / dgen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  33.7 KB  |  1,254 lines

  1. /*
  2.  AnaGram Parsing Engine
  3.  Copyright (c) 1992, Jerome T. Holland.
  4.  All Rights Reserved.
  5. */
  6.  
  7.  
  8. /*  Line 39, D:\C_USR_J\DISTRIB\DGEN.SYN */
  9. #include "tutils.h"
  10.  
  11. #include "dgen.h"
  12. #include <ctype.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx]))
  18. #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx])
  19. #define CONTEXT ((PCB).cs[(PCB).ssx])
  20.  
  21.  
  22. #ifndef NEAR
  23. #define NEAR near
  24. #endif
  25. #ifndef LOCUS
  26. #define LOCUS near
  27. #endif
  28. #ifndef VOID
  29. #define VOID void
  30. #endif
  31. #ifndef CONST
  32. #define CONST const
  33. #endif
  34. #ifndef CONVERT_CASE(c)
  35. #define CONVERT_CASE(c) (c)
  36. #endif
  37. #ifndef TAB_SPACING
  38. #define TAB_SPACING 8
  39. #endif
  40. #define AG_INIT_PARSE() VOID init_dgen(VOID)
  41. #define AG_PARSE() VOID dgen(VOID)
  42. #define AG_INITIALIZE() init_dgen()
  43. #define AG_PARSER_STACK_SIZE     32
  44.  
  45. dgen_pcb_type dgen_pcb;
  46. #define PCB dgen_pcb
  47.  
  48.  
  49. #ifndef DGEN_H
  50. #include "dgen.h"
  51. #endif
  52.  
  53.  
  54. static char * NEAR ag_rp_1(VOID) {
  55. /* Line 63 */
  56.   return release();
  57. }
  58.  
  59. static VOID NEAR ag_rp_2(int c) {
  60. /* Line 65 */
  61.   collectFirst(c);
  62. }
  63.  
  64. static VOID NEAR ag_rp_3(int c) {
  65. /* Line 67 */
  66.   collect(c);
  67. }
  68.  
  69. static VOID NEAR ag_rp_4(int c) {
  70. /* Line 68 */
  71.   collect(c);
  72. }
  73.  
  74. static char * NEAR ag_rp_5(VOID) {
  75. /* Line 71 */
  76.   return release();
  77. }
  78.  
  79. static VOID NEAR ag_rp_6(int c) {
  80. /* Line 73 */
  81.   collectFirst(c);
  82. }
  83.  
  84. static VOID NEAR ag_rp_7(int c) {
  85. /* Line 75 */
  86.   collect(c);
  87. }
  88.  
  89. static char * NEAR ag_rp_8(VOID) {
  90. /* Line 83 */
  91. collect('}');return(release());
  92. }
  93.  
  94. static VOID NEAR ag_rp_9(VOID) {
  95. /* Line 85 */
  96.   collectFirst('{');
  97. }
  98.  
  99. static VOID NEAR ag_rp_10(int c) {
  100. /* Line 87 */
  101.   collect(c);
  102. }
  103.  
  104. static VOID NEAR ag_rp_11(VOID) {
  105. /* Line 91 */
  106.   collect('}');
  107. }
  108.  
  109. static VOID NEAR ag_rp_12(VOID) {
  110. /* Line 93 */
  111.   collect('{');
  112. }
  113.  
  114. static struct STRLIST * NEAR ag_rp_13(char * s) {
  115. /* Line 95 */
  116.   return listNew(s,"");
  117. }
  118.  
  119. static struct STRLIST * NEAR ag_rp_14(struct STRLIST * lst, char * s) {
  120. /* Line 96 */
  121.   return listAdd(lst,s,"");
  122. }
  123.  
  124. static char * NEAR ag_rp_15(VOID) {
  125. /* Line 99 */
  126.   return release();
  127. }
  128.  
  129. static VOID NEAR ag_rp_16(int c) {
  130. /* Line 101 */
  131.   collectFirst(c);
  132. }
  133.  
  134. static VOID NEAR ag_rp_17(int c) {
  135. /* Line 103 */
  136.   collect(c);
  137. }
  138.  
  139. static VOID NEAR ag_rp_18(VOID) {
  140. /* Line 107 */
  141.   writeDriver();
  142. }
  143.  
  144. static VOID NEAR ag_rp_19(char * eb) {
  145. /* Line 116 */
  146.   addBlock(eb);
  147. }
  148.  
  149. static VOID NEAR ag_rp_20(char * n) {
  150. /* Line 130 */
  151.   setRunName(n);
  152. }
  153.  
  154. static VOID NEAR ag_rp_21(struct STRLIST * vl, char * b) {
  155. /* Line 133 */
  156.   makeVary(vl,b);
  157. }
  158.  
  159. static VOID NEAR ag_rp_22(struct STRLIST * vl, char * b) {
  160. /* Line 135 */
  161.   makeComb(vl,b);
  162. }
  163.  
  164. static struct STRLIST * NEAR ag_rp_23(char * v) {
  165. /* Line 137 */
  166.   return listNew(v,"");
  167. }
  168.  
  169. static struct STRLIST * NEAR ag_rp_24(struct STRLIST * lst, char * v) {
  170. /* Line 139 */
  171.   return listAdd(lst,v,"");
  172. }
  173.  
  174. static VOID NEAR ag_rp_25(struct STRLIST * vl, struct STRLIST * il) {
  175. /* Line 160 */
  176.   addTVars(vl,"char","char",il);
  177. }
  178.  
  179. static VOID NEAR ag_rp_26(struct STRLIST * vl, struct STRLIST * il) {
  180. /* Line 169 */
  181.   addTVars(vl,"char *","char *",il);
  182. }
  183.  
  184. static VOID NEAR ag_rp_27(struct STRLIST * vl, struct STRLIST * il) {
  185. /* Line 178 */
  186.   addTVars(vl,"int","int",il);
  187. }
  188.  
  189. static VOID NEAR ag_rp_28(struct STRLIST * vl, struct STRLIST * il) {
  190. /* Line 187 */
  191.   addTVars(vl,"double","double&",il);
  192. }
  193.  
  194. static VOID NEAR ag_rp_29(struct STRLIST * vl, struct STRLIST * il) {
  195. /* Line 196 */
  196.   addTVars(vl,"FILE *","FILE *",il);
  197. }
  198.  
  199. static VOID NEAR ag_rp_30(struct STRLIST * vl, struct STRLIST * il) {
  200. /* Line 207 */
  201.   addTVars(vl,"INTARR2","INTARR2",il);
  202. }
  203.  
  204. static VOID NEAR ag_rp_31(struct STRLIST * vl, struct STRLIST * il) {
  205. /* Line 216 */
  206.   addTVars(vl,"Item","Item&",il);
  207. }
  208.  
  209. static VOID NEAR ag_rp_32(struct STRLIST * vl, struct STRLIST * il) {
  210. /* Line 224 */
  211.   addTVars(vl,"Client","Client&",il);
  212. }
  213.  
  214. static VOID NEAR ag_rp_33(struct STRLIST * vl, struct STRLIST * il) {
  215. /* Line 232 */
  216.   addTVars(vl,"Invoice","Invoice&",il);
  217. }
  218. #define AG_TRACE_ERROR
  219. #define AG_VT dgen_pcb_type
  220. #define AG_COUNT_RULE(k)
  221. static dgen_vs_type ag_null_value;
  222. #define AG_INPUT_TYPE int
  223. #define AG_TOKEN_TYPE dgen_token_type
  224. #define AG_VALUE_STACK_TYPE dgen_vs_type
  225. #define AG_INPUT_VALUE CONVERT_CASE(*PCB.lab)
  226. #define AG_INPUT_CODE (*PCB.lab)
  227. #define V(i,t) (*(t *) (&(PCB).vs[(PCB).ssx + i]))
  228. #define VS(i) (PCB).vs[(PCB).ssx + i]
  229.  
  230. #ifndef AG_GET_VALUE
  231. #define AG_GET_VALUE AG_INPUT = AG_INPUT_VALUE
  232. #endif
  233.  
  234. #ifndef GET_CONTEXT
  235. #define GET_CONTEXT CONTEXT = (PCB).input_context
  236. #endif
  237.  
  238. #ifndef AG_NULL
  239. #define AG_NULL (PCB).vs[(PCB).ssx] = ag_null_value
  240. #endif
  241.  
  242. #ifdef AG_CONTEXT_TYPE
  243. #define AG_SAVE_CONTEXT {GET_CONTEXT;}
  244. #define AG_SWAP_CONTEXT(k1,k2) (PCB).cs[k1] = (PCB).cs[k2]
  245. #endif
  246.  
  247. #ifndef AG_SAVE_CONTEXT
  248. #define AG_SAVE_CONTEXT
  249. #define AG_SWAP_CONTEXT(k1,k2)
  250. #endif
  251.  
  252. typedef enum {
  253.   ag_shift_accept,
  254.   ag_go_to,
  255.   ag_shift_reduce,
  256.   ag_shift_simple_reduce,
  257.   ag_reduce_form,
  258.   ag_simple_reduce,
  259.   ag_accept,
  260.   ag_syn_error,
  261.   ag_null_go_to,
  262.   ag_skip,
  263.   ag_skip_reduce,
  264.   ag_recover
  265. } ag_parser_action;
  266.  
  267. static int ag_ap;
  268.  
  269.  
  270. #define AG_VALUE
  271. #define AG_INPUT (*(int *) &PCB.vs[PCB.ssx])
  272.  
  273. static CONST unsigned char ag_rpx[] = {
  274.     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  2,  3,  4,  5,  6,  7,
  275.     0,  0,  0,  0,  8,  9, 10,  0, 11, 12, 13, 14,  0,  0,  0,  0, 15, 16,
  276.    17,  0,  0, 18,  0,  0,  0, 19,  0, 20, 21, 22, 23, 24,  0,  0,  0,  0,
  277.     0,  0,  0,  0,  0, 25, 26, 27, 28, 29, 30, 31, 32, 33
  278. };
  279.  
  280. static unsigned char ag_key_itt[] = {
  281.   0
  282. };
  283.  
  284. static unsigned short ag_key_pt[] = {
  285. 0
  286. };
  287.  
  288. #define AG_KEY
  289. static unsigned char ag_key_ch[] = {
  290.     0,110,116,255, 97,255,116,255,110,255, 47, 67, 70, 73, 99,100,105,114,
  291.   115,255,110,116,255, 97,255,116,255,110,255, 47, 67, 70, 73, 99,100,105,
  292.   114,115,125,255,110,116,255, 97,255,116,255,110,255, 67, 70, 73, 99,100,
  293.   105,114,115,255, 47,255, 47, 99,118,255,123,255, 47,123,255,125,255, 47,
  294.   125,255
  295. };
  296.  
  297. static unsigned char ag_key_act[] = {
  298.   0,3,3,4,3,4,1,4,2,4,3,3,3,2,3,3,2,3,3,4,3,3,4,3,4,1,4,2,4,3,3,3,2,3,3,
  299.   2,3,3,0,4,3,3,4,3,4,1,4,2,4,3,3,2,3,3,2,3,3,4,3,4,3,3,3,4,0,4,3,0,4,0,
  300.   4,3,0,4
  301. };
  302.  
  303. static unsigned char ag_key_parm[] = {
  304.     0, 69, 67,  0, 66,  0, 63,  0,  0,  0,  5, 68, 65,  0, 59, 64,  0, 46,
  305.    62,  0, 69, 67,  0, 66,  0, 63,  0,  0,  0,  5, 68, 65,  0, 59, 64,  0,
  306.    46, 62, 61,  0, 69, 67,  0, 66,  0, 63,  0,  0,  0, 68, 65,  0, 59, 64,
  307.     0, 46, 62,  0,  5,  0,  5, 49, 47,  0, 60,  0,  5, 60,  0, 61,  0,  5,
  308.    61,  0
  309. };
  310.  
  311. static unsigned char ag_key_jmp[] = {
  312.     0, 12, 18,  0, 31,  0,  4,  0,  6,  0,  0,  2,  8,  1, 21, 25,  8, 35,
  313.    42,  0, 60, 66,  0, 79,  0, 23,  0, 25,  0, 48, 50, 56, 20, 69, 73, 27,
  314.    83, 90,  0,  0,106,112,  0,125,  0, 43,  0, 45,  0, 96,102, 40,115,119,
  315.    47,129,136,  0,142,  0,144,146,155,  0,  0,  0,162,  0,  0,  0,  0,164,
  316.     0,  0
  317. };
  318.  
  319. static unsigned char ag_key_index[] = {
  320.    10,  0, 29, 49,  0,  0, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,  0, 58,
  321.    10, 10, 10, 49, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,  0,  0,  0, 60,
  322.    58, 58, 64, 64, 64, 64, 64, 64, 64, 64, 64,  0,  0, 58, 58, 58, 66, 58,
  323.    58, 58, 58, 58, 58, 58, 58, 58, 58,  0, 58, 58,  0, 66,  0,  0,  0,  0,
  324.     0,  0,  0,  0,  0,  0,  0, 69, 69, 69, 69, 69, 69, 69, 69, 69,  0, 71
  325. };
  326.  
  327. static unsigned char ag_key_ends[] = {
  328. 47,0, 108,105,101,110,116,0, 73,76,69,0, 118,111,105,99,101,0, 
  329. 101,109,0, 104,97,114,0, 111,117,98,108,101,0, 114,114,50,0, 
  330. 117,110,116,101,115,116,0, 116,114,105,110,103,0, 47,0, 
  331. 108,105,101,110,116,0, 73,76,69,0, 118,111,105,99,101,0, 101,109,0, 
  332. 104,97,114,0, 111,117,98,108,101,0, 114,114,50,0, 
  333. 117,110,116,101,115,116,0, 116,114,105,110,103,0, 108,105,101,110,116,0, 
  334. 73,76,69,0, 118,111,105,99,101,0, 101,109,0, 104,97,114,0, 
  335. 111,117,98,108,101,0, 114,114,50,0, 117,110,116,101,115,116,0, 
  336. 116,114,105,110,103,0, 47,0, 47,0, 111,109,98,105,110,105,110,103,0, 
  337. 97,114,121,105,110,103,0, 47,0, 47,0, 
  338. };
  339. #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0)
  340.  
  341. static CONST unsigned char ag_tcv[] = {
  342.    40, 40, 70, 70, 70, 40, 70, 70, 70, 70,  2,  3, 70, 70, 70, 70, 70, 70,
  343.    70, 70, 70, 70, 70, 70, 70, 70, 70, 40, 70, 70, 70, 70, 70,  2, 70, 16,
  344.    70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71,
  345.    71, 71, 71, 71, 71, 70, 70, 70, 70, 70, 70, 70, 13, 13, 13, 13, 13, 13,
  346.    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  347.    13, 13, 31, 70, 33, 70, 13, 70, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  348.    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 25, 70,
  349.    24, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
  350.    70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
  351.    70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
  352.    70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
  353.    70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
  354.    70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
  355.    70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
  356.    70, 70, 70, 70, 70
  357. };
  358.  
  359. #define AG_GET_KEY_WORD() ag_get_key_word(int ag_k)
  360. #define AG_RNS()          ag_rns(int ag_t, int *ag_sx, int ag_snd)
  361. #define AG_JNS()          ag_jns(int ag_t)
  362. #define AG_ATX()          ag_atx(int ag_t, int *ag_sx, int ag_snd)
  363. #define AG_CHECK_DEPTH()  ag_check_depth(int ag_fl)
  364. #define AG_VALID()        ag_valid(int ag_k)
  365. #define AG_DEFAULT()      ag_default(CONST int *ag_tp)
  366.  
  367.  
  368. #ifndef SYNTAX_ERROR
  369. #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n",\
  370.   (PCB).error_message, (PCB).line, (PCB).column)
  371. #endif
  372.  
  373. #ifndef PARSER_STACK_OVERFLOW
  374. #define PARSER_STACK_OVERFLOW {fprintf(stderr,\
  375.    "\nParser stack overflow, line %d, column %d\n",\
  376.    (PCB).line, (PCB).column);}
  377. #endif
  378.  
  379. #define AG_OVERFLOW {AG_TRACE_ERROR; (PCB).exit_flag = AG_STACK_ERROR_CODE;\
  380.         PARSER_STACK_OVERFLOW;}
  381.  
  382. #ifndef REDUCTION_TOKEN_ERROR
  383. #define REDUCTION_TOKEN_ERROR {fprintf(stderr,\
  384.     "\nReduction token error, line %d, column %d\n",\
  385.     (PCB).line, (PCB).column);}
  386. #endif
  387.  
  388.  
  389. typedef enum
  390.   {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key,
  391.    ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words;
  392.  
  393. #define AG_CHAR ((PCB).rx < (PCB).fx ? (PCB).lab[(PCB).rx-1] : (PCB).input_code)
  394. #define AG_INIT_PTR ((PCB).rx = (PCB).fx = 0)
  395. #define AG_RST_PTR ((PCB).rx = 0)
  396. #ifndef GET_INPUT
  397. #define GET_INPUT ((PCB).input_code = getchar())
  398. #endif
  399.  
  400. static NEAR ag_look_ahead(VOID) {
  401.   if ((PCB).rx < (PCB).fx) return (PCB).lab[(PCB).rx++];
  402.   GET_INPUT;
  403.   (PCB).fx++;
  404.   return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code);
  405. }
  406.  
  407. static VOID NEAR AG_GET_KEY_WORD() {
  408.   int save_index = (PCB).rx;
  409.   unsigned char ag_ch, NEAR *sp;
  410.   while (1) {
  411.     switch (ag_key_act[ag_k]) {
  412.     case ag_cf_end_key:
  413.       sp = ag_key_ends + ag_key_jmp[ag_k];
  414.       do {
  415.         if ((ag_ch = *sp++) == 0) {
  416.           int ag_k1 = ag_key_parm[ag_k];
  417.           int ag_k2 = ag_key_pt[ag_k1];
  418.           if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail;
  419.           (PCB).rx--;
  420.           (PCB).token_number = (AG_TOKEN_TYPE) ag_key_pt[ag_k1 + 1];
  421.           return;
  422.         }
  423.       } while (ag_look_ahead() == ag_ch);
  424.       goto ag_fail;
  425.     case ag_end_key:
  426.       sp = ag_key_ends + ag_key_jmp[ag_k];
  427.       do {
  428.         if ((ag_ch = *sp++) == 0) {
  429.           (PCB).token_number = (AG_TOKEN_TYPE) ag_key_parm[ag_k];
  430.           return;
  431.         }
  432.       } while (ag_look_ahead() == ag_ch);
  433.     case ag_no_match_key:
  434. ag_fail:
  435.       (PCB).rx = save_index;
  436.       return;
  437.     case ag_cf_set_key: {
  438.       int ag_k1 = ag_key_parm[ag_k];
  439.       int ag_k2 = ag_key_pt[ag_k1];
  440.       ag_k = ag_key_jmp[ag_k];
  441.       if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break;
  442.       save_index = --(PCB).rx;
  443.       (PCB).token_number = (AG_TOKEN_TYPE) ag_key_pt[ag_k1+1];
  444.       break;
  445.     }
  446.     case ag_set_key:
  447.       save_index = (PCB).rx;
  448.       (PCB).token_number = (AG_TOKEN_TYPE) ag_key_parm[ag_k];
  449.     case ag_jmp_key:
  450.       ag_k = ag_key_jmp[ag_k];
  451.       ag_ch = ag_look_ahead();
  452.       break;
  453.     case ag_accept_key:
  454.       (PCB).token_number =  (AG_TOKEN_TYPE) ag_key_parm[ag_k];
  455.       return;
  456.     case ag_cf_accept_key: {
  457.       int ag_k1 = ag_key_parm[ag_k];
  458.       int ag_k2 = ag_key_pt[ag_k1];
  459.       if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index;
  460.       else {
  461.         (PCB).rx--;
  462.         (PCB).token_number =  (AG_TOKEN_TYPE) ag_key_pt[ag_k1+1];
  463.       }
  464.       return;
  465.     }
  466.     }
  467.     while(ag_key_ch[ag_k] < ag_ch) ag_k++;
  468.     if (ag_key_ch[ag_k] != ag_ch) {
  469.       (PCB).rx = save_index;
  470.       return;
  471.     }
  472.   }
  473. }
  474.  
  475.  
  476. #define AG_TRK_PTR ag_track()
  477. #define AG_INC_PTR {(PCB).rx = 1; ag_track();}
  478. #define AG_INIT_TRK (PCB).line = (PCB).column = 1;
  479.  
  480. static VOID NEAR ag_track(VOID) {
  481.   int ag_k = 0;
  482.   while (ag_k < (PCB).rx) {
  483.     int ag_ch = (PCB).lab[ag_k++];
  484.     switch (ag_ch) {
  485.     case '\n':
  486.       (PCB).column = 1, (PCB).line++;
  487.     case '\r':
  488.     case '\f':
  489.       break;
  490.     case '\t':
  491.       (PCB).column += (TAB_SPACING) + 1 - (PCB).column % (TAB_SPACING);
  492.     default:
  493.       (PCB).column++;
  494.     }
  495.   }
  496.   ag_k = 0;
  497.   while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++];
  498.   (PCB).fx = ag_k;
  499.   (PCB).rx = 0;
  500. }
  501.  
  502.  
  503. #define AG_GET_TKN {\
  504.   if ((PCB).rx < (PCB).fx) {\
  505.     (PCB).input_code = (PCB).lab[(PCB).rx++];\
  506.     (PCB).token_number = (AG_TOKEN_TYPE) AG_TCV((PCB).input_code);}\
  507.   else {\
  508.     GET_INPUT;\
  509.     (PCB).lab[(PCB).fx++] = (PCB).input_code;\
  510.     (PCB).token_number = (AG_TOKEN_TYPE) AG_TCV((PCB).input_code);\
  511.     (PCB).rx++;\
  512.   }\
  513.   {\
  514.     unsigned ag_k = ag_key_index[(PCB).sn];\
  515.     if (ag_k) {\
  516.       unsigned char ag_ch = CONVERT_CASE((PCB).input_code);\
  517.       while (ag_key_ch[ag_k] < ag_ch) ag_k++;\
  518.       if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k);\
  519. } } }
  520.  
  521.  
  522. #define AG_CLEAR_BACK ((PCB).btsx = 0, (PCB).drt = -1);
  523.  
  524. #define AG_STACK {\
  525.   (PCB).ss[(PCB).ssx] = (PCB).sn;\
  526.   AG_SAVE_CONTEXT;}
  527.  
  528. #define AG_CHKOVFLO {if ((PCB).ssx >= AG_PARSER_STACK_SIZE) AG_OVERFLOW;}
  529. #define AG_PROT {if ((PCB).drt >= 0) ag_prot(); else AG_CHKOVFLO;}
  530. #define AG_SET_BACK {if((PCB).drt == -1)\
  531.   (PCB).drt=(PCB).token_number,(PCB).dssx=(PCB).ssx,(PCB).dsn=(PCB).sn;}
  532.  
  533. static VOID NEAR ag_prot(VOID) {
  534.   int ag_k = (AG_PARSER_STACK_SIZE) - ++(PCB).btsx;
  535.   if (ag_k <= (PCB).ssx) {AG_OVERFLOW; return;}
  536.   (PCB).bts[(PCB).btsx] = (PCB).sn;
  537.   (PCB).bts[ag_k] = (PCB).ssx;
  538.   (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
  539.   (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
  540.   AG_SWAP_CONTEXT(ag_k, (PCB).ssx);
  541. }
  542.  
  543. #define AG_UNDO ag_undo()
  544. static VOID NEAR ag_undo(VOID) {
  545.   if ((PCB).drt == -1) return;
  546.   while ((PCB).btsx) {
  547.     int ag_k = (AG_PARSER_STACK_SIZE) - (PCB).btsx;
  548.     (PCB).sn = (PCB).bts[(PCB).btsx--];
  549.     (PCB).ssx = (PCB).bts[ag_k];
  550.     (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
  551.     (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
  552.     AG_SWAP_CONTEXT((PCB).ssx, ag_k);
  553.   }
  554.   (PCB).token_number = (AG_TOKEN_TYPE) (PCB).drt;
  555.   (PCB).ssx = (PCB).dssx;
  556.   (PCB).sn = (PCB).dsn;
  557.   (PCB).drt = -1;
  558. }
  559.  
  560.  
  561.  
  562. #define AG_TSTT_TYPE CONST unsigned char
  563. static AG_TSTT_TYPE LOCUS ag_tstt[] = {
  564. /*000*/5,3,2,0,1,4,34,35,37,
  565. /*001*/71,70,33,31,25,24,16,13,2,0,7,8,
  566. /*002*/5,3,2,0,1,4,
  567. /*003*/69,68,67,66,65,64,63,62,59,46,25,0,19,20,38,39,41,42,43,44,50,51,52,
  568.   53,54,55,56,57,58,
  569. /*004*/71,70,33,31,25,24,16,13,2,0,
  570. /*005*/3,0,
  571. /*006*/5,3,2,0,1,4,34,
  572. /*007*/5,3,2,0,1,4,34,
  573. /*008*/5,3,2,0,1,4,34,
  574. /*009*/5,3,2,0,1,4,34,
  575. /*010*/5,3,2,0,1,4,34,
  576. /*011*/5,3,2,0,1,4,34,
  577. /*012*/5,3,2,0,1,4,34,
  578. /*013*/5,3,2,0,1,4,34,
  579. /*014*/5,3,2,0,1,4,34,
  580. /*015*/5,3,2,0,1,4,34,
  581. /*016*/71,70,33,31,25,16,13,3,2,0,21,22,23,27,28,
  582. /*017*/5,3,2,0,1,4,34,
  583. /*018*/5,3,2,0,1,4,34,35,
  584. /*019*/5,3,2,0,1,4,34,35,
  585. /*020*/5,3,2,0,1,4,34,35,
  586. /*021*/69,68,67,66,65,64,63,62,59,46,40,25,0,19,20,38,41,42,43,44,50,51,52,
  587.   53,54,55,56,57,58,
  588. /*022*/13,5,3,2,0,1,4,9,10,48,
  589. /*023*/13,5,3,2,0,1,4,9,10,48,
  590. /*024*/13,5,3,2,0,1,4,9,10,48,
  591. /*025*/13,5,3,2,0,1,4,9,10,48,
  592. /*026*/13,5,3,2,0,1,4,9,10,48,
  593. /*027*/13,5,3,2,0,1,4,9,10,48,
  594. /*028*/13,5,3,2,0,1,4,9,10,48,
  595. /*029*/13,5,3,2,0,1,4,9,10,48,
  596. /*030*/13,5,3,2,0,1,4,9,10,48,
  597. /*031*/16,5,3,2,0,1,4,15,
  598. /*032*/71,70,33,31,25,16,13,3,2,0,21,22,23,27,28,
  599. /*033*/71,70,33,31,25,16,13,3,2,0,21,27,28,
  600. /*034*/24,0,
  601. /*035*/49,47,5,3,2,0,1,4,45,
  602. /*036*/71,13,0,11,12,
  603. /*037*/5,3,2,0,1,4,34,
  604. /*038*/60,13,0,9,10,
  605. /*039*/60,13,0,9,10,
  606. /*040*/60,13,0,9,10,
  607. /*041*/60,13,0,9,10,
  608. /*042*/60,13,0,9,10,
  609. /*043*/60,13,0,9,10,
  610. /*044*/60,13,0,9,10,
  611. /*045*/60,13,0,9,10,
  612. /*046*/60,13,0,9,10,
  613. /*047*/71,70,33,31,25,24,13,2,0,17,
  614. /*048*/24,0,
  615. /*049*/5,3,2,0,1,4,34,
  616. /*050*/5,3,2,0,1,4,34,
  617. /*051*/71,13,0,
  618. /*052*/5,3,2,0,1,4,
  619. /*053*/5,3,2,0,1,4,34,35,
  620. /*054*/5,3,2,0,1,4,34,
  621. /*055*/5,3,2,0,1,4,34,35,
  622. /*056*/5,3,2,0,1,4,34,35,
  623. /*057*/5,3,2,0,1,4,34,35,
  624. /*058*/5,3,2,0,1,4,34,35,
  625. /*059*/5,3,2,0,1,4,34,35,
  626. /*060*/5,3,2,0,1,4,34,35,
  627. /*061*/5,3,2,0,1,4,34,35,
  628. /*062*/5,3,2,0,1,4,34,35,
  629. /*063*/71,70,33,31,25,24,16,13,2,0,
  630. /*064*/13,5,3,2,0,1,4,9,10,48,
  631. /*065*/13,5,3,2,0,1,4,9,10,48,
  632. /*066*/31,0,29,30,
  633. /*067*/5,3,2,0,1,4,
  634. /*068*/31,0,29,30,
  635. /*069*/31,0,29,30,
  636. /*070*/31,0,29,30,
  637. /*071*/31,0,29,30,
  638. /*072*/31,0,29,30,
  639. /*073*/31,0,29,30,
  640. /*074*/31,0,29,30,
  641. /*075*/31,0,29,30,
  642. /*076*/25,13,0,9,10,19,20,
  643. /*077*/25,13,0,9,10,19,20,
  644. /*078*/71,70,40,31,25,24,16,13,3,2,0,32,
  645. /*079*/61,31,0,30,
  646. /*080*/61,31,0,30,
  647. /*081*/61,31,0,30,
  648. /*082*/61,31,0,30,
  649. /*083*/61,31,0,30,
  650. /*084*/61,31,0,30,
  651. /*085*/61,31,0,30,
  652. /*086*/61,31,0,30,
  653. /*087*/61,31,0,30,
  654. /*088*/71,70,40,33,31,25,24,16,13,3,2,0,
  655. /*089*/5,3,2,0,1,4,34,35,
  656.  
  657. };
  658.  
  659.  
  660. static unsigned char LOCUS ag_astt[675] = {
  661.   1,1,1,8,1,1,1,1,0,1,1,1,1,1,1,1,1,1,8,1,1,1,9,9,5,3,3,1,1,1,1,1,1,1,1,1,1,
  662.   2,7,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,5,3,7,1,1,1,7,1,1,
  663.   1,1,1,1,7,1,1,1,1,1,1,7,1,1,1,1,1,1,7,1,1,1,1,1,1,7,1,1,1,1,1,1,7,1,1,1,1,
  664.   1,1,7,1,1,1,1,1,1,7,1,1,1,1,1,1,7,1,1,1,1,1,1,7,1,1,1,2,2,2,2,2,2,2,2,2,8,
  665.   1,1,1,1,1,1,1,1,7,1,1,1,1,1,1,5,1,1,1,3,1,1,1,5,1,1,1,3,1,1,1,5,1,1,1,3,1,
  666.   1,1,1,1,1,1,1,1,1,2,2,7,2,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,9,9,7,3,3,1,1,
  667.   1,2,1,9,9,7,3,3,1,1,1,2,1,9,9,7,3,3,1,1,1,2,1,9,9,7,3,3,1,1,1,2,1,9,9,7,3,
  668.   3,1,1,1,2,1,9,9,7,3,3,1,1,1,2,1,9,9,7,3,3,1,1,1,2,1,9,9,7,3,3,1,1,1,2,1,9,
  669.   9,7,3,3,1,1,1,1,1,9,9,7,3,3,2,2,2,2,2,2,2,2,2,2,8,1,1,1,1,1,2,2,2,2,2,2,2,
  670.   2,2,5,3,3,1,2,7,1,1,1,9,9,7,3,3,3,2,2,5,1,2,1,1,1,7,1,1,1,1,2,7,1,1,1,2,7,
  671.   1,1,1,2,7,1,1,1,2,7,1,1,1,2,7,1,1,1,2,7,1,1,1,2,7,1,1,1,2,7,1,1,1,2,7,1,1,
  672.   2,2,2,2,2,2,2,2,7,1,2,7,1,1,1,7,1,1,1,1,1,1,7,1,1,1,10,10,5,1,9,9,4,3,3,1,
  673.   1,1,8,1,1,1,1,1,1,1,7,1,1,1,1,1,1,8,1,1,1,1,1,1,1,8,1,1,1,1,1,1,1,8,1,1,1,
  674.   1,1,1,1,8,1,1,1,1,1,1,1,8,1,1,1,1,1,1,1,8,1,1,1,1,1,1,1,8,1,1,1,1,1,1,1,8,
  675.   1,1,1,1,10,10,10,10,10,10,2,10,10,7,2,1,9,9,7,3,3,1,1,1,2,1,9,9,7,3,3,1,1,
  676.   1,1,7,1,2,1,9,9,4,3,3,1,7,1,2,1,7,1,2,1,7,1,2,1,7,1,2,1,7,1,2,1,7,1,2,1,7,
  677.   1,2,1,7,1,2,2,2,7,1,1,2,1,2,2,7,1,1,2,1,2,2,2,2,2,2,2,2,2,2,7,1,2,1,7,2,2,
  678.   1,7,2,2,1,7,2,2,1,7,2,2,1,7,2,2,1,7,2,2,1,7,2,2,1,7,2,2,1,7,2,10,10,10,1,
  679.   10,10,10,10,10,10,10,7,1,1,1,5,1,1,1,2
  680. };
  681.  
  682.  
  683. static unsigned char LOCUS ag_pstt[] = {
  684. /*000*/1,2,2,3,2,2,2,3,0,
  685. /*001*/4,4,4,4,4,4,4,4,4,5,4,5,
  686. /*002*/1,31,31,33,31,31,
  687. /*003*/6,7,8,9,10,11,12,13,14,15,23,3,43,16,21,21,20,19,18,17,18,18,18,18,
  688.   18,18,18,18,18,
  689. /*004*/5,5,5,5,5,5,5,5,5,7,
  690. /*005*/8,5,
  691. /*006*/1,22,22,6,22,22,22,
  692. /*007*/1,23,23,7,23,23,23,
  693. /*008*/1,24,24,8,24,24,24,
  694. /*009*/1,25,25,9,25,25,25,
  695. /*010*/1,26,26,10,26,26,26,
  696. /*011*/1,27,27,11,27,27,27,
  697. /*012*/1,28,28,12,28,28,28,
  698. /*013*/1,29,29,13,29,29,29,
  699. /*014*/1,30,30,14,30,30,30,
  700. /*015*/1,31,31,15,31,31,31,
  701. /*016*/24,24,24,24,27,24,24,24,24,34,33,33,34,33,32,
  702. /*017*/1,35,35,17,35,35,35,
  703. /*018*/1,2,2,32,2,2,2,42,
  704. /*019*/1,2,2,32,2,2,2,41,
  705. /*020*/1,2,2,32,2,2,2,40,
  706. /*021*/6,7,8,9,10,11,12,13,14,15,39,23,21,43,16,38,20,19,18,17,18,18,18,18,
  707.   18,18,18,18,18,
  708. /*022*/12,1,31,31,22,31,31,37,36,38,
  709. /*023*/12,1,31,31,23,31,31,37,36,39,
  710. /*024*/12,1,31,31,24,31,31,37,36,40,
  711. /*025*/12,1,31,31,25,31,31,37,36,41,
  712. /*026*/12,1,31,31,26,31,31,37,36,42,
  713. /*027*/12,1,31,31,27,31,31,37,36,43,
  714. /*028*/12,1,31,31,28,31,31,37,36,44,
  715. /*029*/12,1,31,31,29,31,31,37,36,45,
  716. /*030*/12,1,31,31,30,31,31,37,36,46,
  717. /*031*/47,1,31,31,31,31,31,45,
  718. /*032*/24,24,24,24,27,24,24,24,24,48,33,33,48,33,32,
  719. /*033*/24,24,24,24,27,24,24,24,24,21,19,19,32,
  720. /*034*/22,34,
  721. /*035*/49,50,1,31,31,35,31,31,44,
  722. /*036*/13,13,9,51,11,
  723. /*037*/1,52,52,37,52,52,52,
  724. /*038*/53,12,38,54,36,
  725. /*039*/55,12,39,54,36,
  726. /*040*/56,12,40,54,36,
  727. /*041*/57,12,41,54,36,
  728. /*042*/58,12,42,54,36,
  729. /*043*/59,12,43,54,36,
  730. /*044*/60,12,44,54,36,
  731. /*045*/61,12,45,54,36,
  732. /*046*/62,12,46,54,36,
  733. /*047*/16,16,16,16,16,16,16,16,47,63,
  734. /*048*/26,48,
  735. /*049*/1,64,64,49,64,64,64,
  736. /*050*/1,65,65,50,65,65,65,
  737. /*051*/14,14,10,
  738. /*052*/1,31,31,48,31,31,
  739. /*053*/1,2,2,66,2,2,2,66,
  740. /*054*/1,67,67,54,67,67,67,
  741. /*055*/1,2,2,68,2,2,2,68,
  742. /*056*/1,2,2,69,2,2,2,69,
  743. /*057*/1,2,2,70,2,2,2,70,
  744. /*058*/1,2,2,71,2,2,2,71,
  745. /*059*/1,2,2,72,2,2,2,72,
  746. /*060*/1,2,2,73,2,2,2,73,
  747. /*061*/1,2,2,74,2,2,2,74,
  748. /*062*/1,2,2,75,2,2,2,75,
  749. /*063*/17,17,17,17,17,17,15,17,17,63,
  750. /*064*/12,1,31,31,64,31,31,37,36,76,
  751. /*065*/12,1,31,31,65,31,31,37,36,77,
  752. /*066*/78,66,79,28,
  753. /*067*/1,31,31,49,31,31,
  754. /*068*/78,68,80,28,
  755. /*069*/78,69,81,28,
  756. /*070*/78,70,82,28,
  757. /*071*/78,71,83,28,
  758. /*072*/78,72,84,28,
  759. /*073*/78,73,85,28,
  760. /*074*/78,74,86,28,
  761. /*075*/78,75,87,28,
  762. /*076*/23,12,76,54,36,47,16,
  763. /*077*/23,12,77,54,36,46,16,
  764. /*078*/35,35,35,35,35,35,35,35,35,35,78,88,
  765. /*079*/67,78,79,29,
  766. /*080*/66,78,80,29,
  767. /*081*/65,78,81,29,
  768. /*082*/64,78,82,29,
  769. /*083*/63,78,83,29,
  770. /*084*/62,78,84,29,
  771. /*085*/61,78,85,29,
  772. /*086*/60,78,86,29,
  773. /*087*/59,78,87,29,
  774. /*088*/36,36,36,89,36,36,36,36,36,36,36,88,
  775. /*089*/1,2,2,32,2,2,2,34,
  776.  
  777. };
  778.  
  779.  
  780. static CONST unsigned short ag_sbt[] = {
  781.      0,   9,  21,  27,  56,  66,  68,  75,  82,  89,  96, 103, 110, 117,
  782.    124, 131, 138, 153, 160, 168, 176, 184, 213, 223, 233, 243, 253, 263,
  783.    273, 283, 293, 303, 311, 326, 339, 341, 350, 355, 362, 367, 372, 377,
  784.    382, 387, 392, 397, 402, 407, 417, 419, 426, 433, 436, 442, 450, 457,
  785.    465, 473, 481, 489, 497, 505, 513, 521, 531, 541, 551, 555, 561, 565,
  786.    569, 573, 577, 581, 585, 589, 593, 600, 607, 619, 623, 627, 631, 635,
  787.    639, 643, 647, 651, 655, 667, 675
  788. };
  789.  
  790.  
  791. static CONST unsigned short ag_sbe[] = {
  792.      3,  18,  24,  38,  65,  67,  71,  78,  85,  92,  99, 106, 113, 120,
  793.    127, 134, 147, 156, 163, 171, 179, 196, 217, 227, 237, 247, 257, 267,
  794.    277, 287, 297, 307, 320, 335, 340, 346, 352, 358, 364, 369, 374, 379,
  795.    384, 389, 394, 399, 404, 415, 418, 422, 429, 435, 439, 445, 453, 460,
  796.    468, 476, 484, 492, 500, 508, 516, 530, 535, 545, 552, 558, 562, 566,
  797.    570, 574, 578, 582, 586, 590, 595, 602, 617, 621, 625, 629, 633, 637,
  798.    641, 645, 649, 653, 666, 670, 675
  799. };
  800.  
  801.  
  802. static CONST unsigned char ag_fl[] = {
  803.   1,1,1,1,1,2,0,1,3,0,1,2,1,1,2,3,1,2,1,2,0,1,3,1,1,1,3,1,1,2,1,2,0,1,4,
  804.   1,2,1,2,3,2,2,2,1,3,3,4,4,2,3,1,1,1,1,1,1,1,1,1,7,7,7,7,7,7,7,7,7
  805. };
  806.  
  807. static CONST unsigned char ag_ptt[] = {
  808.     0,  1,  1,  1,  7,  7,  8,  8,  4, 12, 12,  9, 10, 11, 11, 15, 17, 17,
  809.    22, 22, 23, 23, 19, 20, 21, 21, 27, 28, 29, 29, 34, 34, 35, 35, 30, 32,
  810.    32, 39, 39, 37, 38, 38, 38, 41, 42, 44, 45, 45, 48, 48, 43, 43, 43, 43,
  811.    43, 43, 43, 43, 43, 50, 51, 52, 53, 54, 55, 56, 57, 58
  812. };
  813.  
  814. #define AG_REDUCE(ag_k) AG_COUNT_RULE(ag_k);\
  815.   (PCB).reduction_token = (AG_TOKEN_TYPE) ag_ptt[ag_k];\
  816.   ag_ra();
  817.  
  818. #define AG_SIMPLE_REDUCE(ag_k) AG_COUNT_RULE(ag_k);\
  819.   (PCB).reduction_token = (AG_TOKEN_TYPE) ag_ptt[ag_k];
  820.  
  821. #define AG_NSR(procs) while (1) {\
  822.     unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;\
  823.     unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;\
  824.     do {\
  825.       unsigned ag_tx = (ag_t1 + ag_t2)/2;\
  826.       if (ag_tstt[ag_tx] < (AG_TSTT_TYPE)(PCB).reduction_token) ag_t1 = ag_tx + 1;\
  827.       else ag_t2 = ag_tx;\
  828.     } while (ag_t1 < ag_t2);\
  829.     ag_ap = ag_pstt[ag_t1];\
  830.     if ((procs[ag_astt[ag_t1]])() == 0) break;\
  831.   }
  832.  
  833.  
  834.  
  835. static VOID NEAR ag_ra(VOID)
  836. {
  837.   switch(ag_rpx[ag_ap]) {
  838.   case   1: V(0,char *) = ag_rp_1(); break;
  839.   case   2: ag_rp_2(V(0,int)); break;
  840.   case   3: ag_rp_3(V(0,int)); break;
  841.   case   4: ag_rp_4(V(1,int)); break;
  842.   case   5: V(0,char *) = ag_rp_5(); break;
  843.   case   6: ag_rp_6(V(0,int)); break;
  844.   case   7: ag_rp_7(V(1,int)); break;
  845.   case   8: V(0,char *) = ag_rp_8(); break;
  846.   case   9: ag_rp_9(); break;
  847.   case  10: ag_rp_10(V(0,int)); break;
  848.   case  11: ag_rp_11(); break;
  849.   case  12: ag_rp_12(); break;
  850.   case  13: V(0,struct STRLIST *) = ag_rp_13(V(0,char *)); break;
  851.   case  14: V(0,struct STRLIST *) = ag_rp_14(V(0,struct STRLIST *), V(1,char *)); break;
  852.   case  15: V(0,char *) = ag_rp_15(); break;
  853.   case  16: ag_rp_16(V(0,int)); break;
  854.   case  17: ag_rp_17(V(1,int)); break;
  855.   case  18: ag_rp_18(); break;
  856.   case  19: ag_rp_19(V(0,char *)); break;
  857.   case  20: ag_rp_20(V(2,char *)); break;
  858.   case  21: ag_rp_21(V(2,struct STRLIST *), V(3,char *)); break;
  859.   case  22: ag_rp_22(V(2,struct STRLIST *), V(3,char *)); break;
  860.   case  23: V(0,struct STRLIST *) = ag_rp_23(V(0,char *)); break;
  861.   case  24: V(0,struct STRLIST *) = ag_rp_24(V(0,struct STRLIST *), V(1,char *)); break;
  862.   case  25: ag_rp_25(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  863.   case  26: ag_rp_26(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  864.   case  27: ag_rp_27(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  865.   case  28: ag_rp_28(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  866.   case  29: ag_rp_29(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  867.   case  30: ag_rp_30(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  868.   case  31: ag_rp_31(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  869.   case  32: ag_rp_32(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  870.   case  33: ag_rp_33(V(2,struct STRLIST *), V(5,struct STRLIST *)); break;
  871.   }
  872. }
  873.  
  874.  
  875. #define TOKEN_NAMES dgen_token_names
  876. CONST char *TOKEN_NAMES[72] = {
  877.   "grammar",
  878.   "space",
  879.   "blank",
  880.   "eol",
  881.   "comment",
  882.   "//",
  883.   "commentCharacter",
  884.   "",
  885.   "",
  886.   "variable",
  887.   "varStart",
  888.   "varRest",
  889.   "",
  890.   "alpha",
  891.   "alphanumeric",
  892.   "string",
  893.   "doubleQuote",
  894.   "stringContents",
  895.   "stringCharacter",
  896.   "block",
  897.   "blockStart",
  898.   "blockComponent",
  899.   "",
  900.   "",
  901.   "'}'",
  902.   "'{'",
  903.   "blockCharacter",
  904.   "nestedBlock",
  905.   "nestStart",
  906.   "initializerList",
  907.   "initializer",
  908.   "'['",
  909.   "initializer contents",
  910.   "']'",
  911.   "",
  912.   "",
  913.   "notCloseBracket",
  914.   "grammar",
  915.   "statement",
  916.   "",
  917.   "eof",
  918.   "embeddedBlock",
  919.   "runStatement",
  920.   "declaration",
  921.   "runHeader",
  922.   "testSpec",
  923.   "runtest",
  924.   "varying",
  925.   "variableList",
  926.   "combining",
  927.   "charDeclaration",
  928.   "stringDeclaration",
  929.   "intDeclaration",
  930.   "doubleDeclaration",
  931.   "FILEDeclaration",
  932.   "intarr2Declaration",
  933.   "ItemDeclaration",
  934.   "ClientDeclaration",
  935.   "InvoiceDeclaration",
  936.   "char",
  937.   "{",
  938.   "}",
  939.   "string",
  940.   "int",
  941.   "double",
  942.   "FILE",
  943.   "intarr2",
  944.   "Item",
  945.   "Client",
  946.   "Invoice",
  947.   "",
  948.   "",
  949.  
  950. };
  951.  
  952. #define AG_DIAGNOSE ag_diagnose()
  953.  
  954. static char ag_msg[82];
  955. static char ag_mst[] = "Missing %s";
  956. static char ag_uet[] = "Unexpected %s";
  957. static char ag_ac[4] = "' '";
  958.  
  959. static VOID NEAR ag_diagnose(VOID) {
  960.   int ag_snd = (PCB).sn, ag_k;
  961.   CONST char *ag_p;
  962.   CONST char *ag_fmt = ag_uet;
  963.  
  964.   ag_k = ag_sbt[ag_snd];
  965.   if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_syn_error) {
  966.     ag_p = TOKEN_NAMES[ag_tstt[ag_k]];
  967.     ag_fmt = ag_mst;
  968.   }
  969.   else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) {
  970.     ag_p = TOKEN_NAMES[(PCB).token_number];
  971.   }
  972.   else if (isprint(AG_INPUT_CODE) && AG_INPUT_CODE != '\\') {
  973.     ag_ac[1] = AG_INPUT_CODE;
  974.     ag_p = ag_ac;
  975.   }
  976.   else ag_p = NULL;
  977.   sprintf(ag_msg, ag_fmt, ag_p ? ag_p : "input");
  978.   (PCB).error_message = ag_msg;
  979.  
  980.  
  981. }
  982. #define AG_RECOVER ag_error_proc
  983. static int NEAR ag_r_shift_accept_proc(VOID);
  984. static int NEAR ag_r_go_to_proc(VOID);
  985. static int NEAR ag_r_shift_reduce_proc(VOID);
  986. static int NEAR ag_r_simple_shift_reduce_proc(VOID);
  987. static int NEAR ag_s_shift_accept_proc(VOID);
  988. static int NEAR ag_s_shift_reduce_proc(VOID);
  989. static int NEAR ag_shift_accept_proc(VOID);
  990. static int NEAR ag_go_to_proc(VOID);
  991. static int NEAR ag_shift_reduce_proc(VOID);
  992. static int NEAR ag_simple_shift_reduce_proc(VOID);
  993. static int NEAR ag_reduce_proc(VOID);
  994. static int NEAR ag_simple_reduce_proc(VOID);
  995. static int NEAR ag_accept_proc(VOID);
  996. static int NEAR ag_error_proc(VOID);
  997. static int NEAR ag_null_go_to_proc(VOID);
  998. static int NEAR ag_skip_proc(VOID);
  999. static int NEAR ag_skip_reduce_proc(VOID);
  1000. static int NEAR AG_RECOVER(VOID);
  1001.  
  1002. static int (NEAR *ag_r_procs_scan[])(VOID) = {
  1003.   ag_r_shift_accept_proc,
  1004.   ag_r_go_to_proc,
  1005.   ag_r_shift_reduce_proc,
  1006.   ag_r_simple_shift_reduce_proc
  1007. };
  1008.  
  1009. static int (NEAR *ag_s_procs_scan[])(VOID) = {
  1010.   ag_s_shift_accept_proc,
  1011.   ag_r_go_to_proc,
  1012.   ag_s_shift_reduce_proc,
  1013.   ag_r_simple_shift_reduce_proc
  1014. };
  1015.  
  1016. static int (NEAR *ag_gt_procs_scan[])(VOID) = {
  1017.   ag_shift_accept_proc,
  1018.   ag_go_to_proc,
  1019.   ag_shift_reduce_proc,
  1020.   ag_simple_shift_reduce_proc,
  1021.   ag_reduce_proc,
  1022.   ag_simple_reduce_proc,
  1023.   ag_accept_proc,
  1024.   ag_error_proc,
  1025.   ag_null_go_to_proc,
  1026.   ag_skip_proc,
  1027.   ag_skip_reduce_proc,
  1028.   AG_RECOVER
  1029. };
  1030.  
  1031.  
  1032. #define AG_GT ag_gt_procs_scan
  1033. #define AG_SR ag_s_procs_scan
  1034. #define AG_RD ag_r_procs_scan
  1035.  
  1036.  
  1037. #define AG_RESYNCH {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE;\
  1038.         AG_DIAGNOSE; SYNTAX_ERROR; AG_INC_PTR;}
  1039. #define AG_INIT_RESYNCH
  1040.  
  1041.  
  1042. #define AG_REDUCE_ACTION(ag_k) AG_COUNT_RULE(ag_k);\
  1043.   (PCB).reduction_token = (AG_TOKEN_TYPE) ag_ptt[ag_k];\
  1044.   ag_ra();
  1045.  
  1046. static int NEAR ag_skip_proc(VOID) {
  1047.   int ag_t = (PCB).token_number;
  1048.   AG_COUNT_RULE(ag_ap);
  1049.   AG_CLEAR_BACK;
  1050.   do {
  1051.     AG_COUNT_RULE(ag_ap);
  1052.     AG_TRK_PTR;
  1053.     AG_GET_TKN;
  1054.   } while ((PCB).token_number == (AG_TOKEN_TYPE) ag_t);
  1055.   AG_RST_PTR;
  1056.   return 1;
  1057. }
  1058.  
  1059. static int NEAR ag_skip_reduce_proc(VOID) {
  1060.   int ag_t = (PCB).token_number;
  1061.  
  1062.   AG_COUNT_RULE(ag_ap);
  1063.   AG_CLEAR_BACK;
  1064.   do {
  1065.     AG_GET_VALUE;
  1066.     (PCB).ssx--;
  1067.     AG_TRK_PTR;
  1068.     ag_ra();
  1069.     (PCB).ssx++;
  1070.     AG_GET_TKN;
  1071.   }
  1072.   while ((PCB).token_number == (AG_TOKEN_TYPE) ag_t);
  1073.   AG_RST_PTR;
  1074.   return 1;
  1075. }
  1076.  
  1077. static int NEAR ag_r_shift_reduce_proc(VOID) {
  1078.   int ag_sd = ag_fl[ag_ap] - 1;
  1079.   if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  1080.   AG_REDUCE(ag_ap);
  1081.   return 1;
  1082. }
  1083.  
  1084. static int NEAR ag_s_shift_reduce_proc(VOID) {
  1085.   int ag_sd = ag_fl[ag_ap] - 1;
  1086.   if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  1087.   AG_REDUCE(ag_ap);
  1088.   return 1;
  1089. }
  1090.  
  1091. static int NEAR ag_r_simple_shift_reduce_proc(VOID) {
  1092.   int ag_sd = ag_fl[ag_ap] - 1;
  1093.   if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  1094.   AG_SIMPLE_REDUCE(ag_ap);
  1095.   return 1;
  1096. }
  1097.  
  1098. static int NEAR ag_go_to_proc(VOID) {
  1099.   AG_CLEAR_BACK;
  1100.   AG_CHKOVFLO;
  1101.   AG_GET_VALUE;
  1102.   AG_STACK;
  1103.   (PCB).ssx++;
  1104.   (PCB).sn = ag_ap;
  1105.   AG_TRK_PTR;
  1106.   return 0;
  1107. }
  1108.  
  1109. static int NEAR ag_null_go_to_proc(VOID) {
  1110.   AG_PROT;
  1111.   AG_NULL;
  1112.   AG_STACK;
  1113.   (PCB).ssx++;
  1114.   (PCB).sn = ag_ap;
  1115.   AG_RST_PTR;
  1116.   return (PCB).exit_flag == AG_RUNNING_CODE;
  1117. }
  1118.  
  1119. static int NEAR ag_r_go_to_proc(VOID) {
  1120.   (PCB).ssx++;
  1121.   (PCB).sn = ag_ap;
  1122.   return 0;
  1123. }
  1124.  
  1125. static int NEAR ag_accept_proc(VOID) {
  1126.   --(PCB).ssx;
  1127.   AG_RST_PTR;
  1128.   AG_COUNT_RULE(0);
  1129.   (PCB).exit_flag = AG_SUCCESS_CODE;
  1130.   return 0;
  1131. }
  1132.  
  1133. static int NEAR ag_shift_accept_proc(VOID) {
  1134.   AG_TRK_PTR;
  1135.   AG_COUNT_RULE(0);
  1136.   (PCB).exit_flag = AG_SUCCESS_CODE;
  1137.   return 0;
  1138. }
  1139.  
  1140. static int NEAR ag_r_shift_accept_proc(VOID) {
  1141.   AG_COUNT_RULE(0);
  1142.   (PCB).exit_flag = AG_SUCCESS_CODE;
  1143.   return 0;
  1144. }
  1145.  
  1146. static int NEAR ag_s_shift_accept_proc(VOID) {
  1147.   AG_COUNT_RULE(0);
  1148.   (PCB).exit_flag = AG_SUCCESS_CODE;
  1149.   return 0;
  1150. }
  1151.  
  1152. static int NEAR ag_simple_shift_reduce_proc(VOID) {
  1153.   int ag_sd = ag_fl[ag_ap] - 1;
  1154.   AG_SIMPLE_REDUCE(ag_ap);
  1155.   AG_CLEAR_BACK;
  1156.   AG_GET_VALUE;
  1157.   if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  1158.   else {AG_STACK;}
  1159.   AG_TRK_PTR;
  1160.   AG_NSR(AG_SR);
  1161.   return 0;
  1162. }
  1163.  
  1164. static int NEAR ag_shift_reduce_proc(VOID) {
  1165.   int ag_sd = ag_fl[ag_ap] - 1;
  1166.   AG_CLEAR_BACK;
  1167.   AG_GET_VALUE;
  1168.   if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  1169.   else {AG_STACK;}
  1170.   AG_TRK_PTR;
  1171.   AG_REDUCE(ag_ap);
  1172.   AG_NSR(AG_SR);
  1173.   return 0;
  1174. }
  1175.  
  1176. static int NEAR ag_error_proc(VOID) {
  1177.   AG_UNDO;
  1178.   AG_TRACE_ERROR;
  1179.   AG_RST_PTR;
  1180.   AG_RESYNCH;
  1181.   AG_RST_PTR;
  1182.   return (PCB).exit_flag == AG_RUNNING_CODE;
  1183. }
  1184.  
  1185. static int NEAR ag_reduce_proc(VOID) {
  1186.   int ag_sd = ag_fl[ag_ap];
  1187.   if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  1188.   else {AG_PROT; AG_STACK;}
  1189.   AG_RST_PTR;
  1190.   AG_REDUCE(ag_ap);
  1191.   AG_NSR(AG_RD);
  1192.   return (PCB).exit_flag == AG_RUNNING_CODE;
  1193. }
  1194.  
  1195. static int NEAR ag_simple_reduce_proc(VOID) {
  1196.   int ag_sd = ag_fl[ag_ap];
  1197.   AG_SIMPLE_REDUCE(ag_ap);
  1198.   if (ag_sd) {
  1199.     AG_SET_BACK;
  1200.     (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  1201.   }
  1202.   else {
  1203.     AG_PROT;
  1204.     AG_NULL;
  1205.     AG_STACK;
  1206.   }
  1207.   AG_RST_PTR;
  1208.   AG_NSR(AG_RD);
  1209.   return (PCB).exit_flag == AG_RUNNING_CODE;
  1210. }
  1211.  
  1212.  
  1213. #ifdef AG_PARSE_VALUE
  1214. AG_PARSE_VALUE() {
  1215.   return AG_VALUE;
  1216. }
  1217. #endif
  1218.  
  1219. AG_INIT_PARSE() {
  1220.   AG_INIT_PTR;
  1221.   AG_INIT_RESYNCH;
  1222.   (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
  1223.   (PCB).exit_flag = AG_RUNNING_CODE;
  1224.   AG_INIT_TRK;
  1225.   AG_CLEAR_BACK;
  1226. }
  1227.  
  1228. AG_PARSE() {
  1229.   AG_INITIALIZE();
  1230.   (PCB).exit_flag = AG_RUNNING_CODE;
  1231.   while ((PCB).exit_flag == AG_RUNNING_CODE) {
  1232.     unsigned ag_t1 = ag_sbt[(PCB).sn];
  1233.     if (ag_tstt[ag_t1]) {
  1234.       unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
  1235.       AG_GET_TKN;
  1236.       do {
  1237.         unsigned ag_tx = (ag_t1 + ag_t2)/2;
  1238.         if (ag_tstt[ag_tx] > (AG_TSTT_TYPE)(PCB).token_number)
  1239.           ag_t1 = ag_tx + 1;
  1240.         else ag_t2 = ag_tx;
  1241.       } while (ag_t1 < ag_t2);
  1242.       if (ag_tstt[ag_t1] != (AG_TSTT_TYPE)(PCB).token_number)
  1243.         ag_t1 = ag_sbe[(PCB).sn];
  1244.     }
  1245.     ag_ap = ag_pstt[ag_t1];
  1246.     (AG_GT[ag_astt[ag_t1]])();
  1247.   }
  1248. }
  1249.  
  1250.  
  1251.  
  1252. VOID main() {
  1253.   dgen();
  1254. }